#include<bits/stdc++.h>
using namespace std;
int n,m,q,u[214514],v[214514],i,j,fa[214514],ava[3555],k,x,fu,fv,vis[214514],d[214514];
int find(int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
vector<int> e[214514],ue;
map<pair<int,int>,int> ma;
unordered_set<int> ring[3];
void dfs(int u,int f)
{
	fa[u]=f;
	d[u]=d[f]+1;
	vis[u]=1;
	for(auto v:e[u]) if(v!=f)
	{
		if(!vis[v]) dfs(v,u);
		else ue.push_back(ma[{v,u}]);
	}
}
void lca(int x,int y)
{
	if(d[x]<d[y]) swap(x,y);
	while(d[x]>d[y]) ring[i].insert(ma[{x,fa[x]}]),x=fa[x];
	while(x!=y)
	{
		ring[i].insert(ma[{x,fa[x]}]),x=fa[x];
		ring[i].insert(ma[{y,fa[y]}]),y=fa[y];
	}
}
int main()
{
	freopen("graph.in","r",stdin);
	freopen("graph.out","w",stdout);
	cin>>n>>m;
	if(m<=3000&&q<=3000)
	{
		for(i=1;i<=m;i++) cin>>u[i]>>v[i];
		cin>>q;
		while(q--)
		{
			for(i=1;i<=m;i++) fa[i]=i,ava[i]=1;
			cin>>k;
			while(k--) cin>>x,ava[x]=0;
			for(i=1;i<=m;i++) if(ava[i]&&find(u[i])!=find(v[i])) fu=find(u[i]),fv=find(v[i]),fa[fu]=fv;
			int tg=1;
			for(i=2;i<=n;i++) if(find(i)!=find(1)) tg=0;
			puts(tg?"YES":"NO");
		}
		return 0;
	}
	if(m<=n+1)
	{
		for(i=1;i<=m;i++)
		{
			cin>>u[i]>>v[i];
			ma[{u[i],v[i]}]=ma[{v[i],u[i]}]=i;
			e[u[i]].push_back(v[i]),e[v[i]].push_back(u[i]);
		}
		dfs(1,0);
		i=0;
		for(auto x:ue)
		{
			ring[++i].insert(x);
			lca(u[x],v[x]);
		}
		cin>>q;
		for(int ac=1;ac<=q;ac++)
		{
			int u,v;
			cin>>k;
			int ans=1;
			if(k>m+1-n)
			{
				ans=0;
				for(i=1;i<=k;i++) cin>>u;
			}
			else if(k==1)
			{
				cin>>u;
				if(ring[1].find(u)==ring[1].end()&&ring[2].find(u)==ring[2].end()) ans=0;
			}
			else
			{
				cin>>u>>v;
				if(!(ring[1].find(u)!=ring[1].end()&&ring[2].find(v)!=ring[2].end()||ring[1].find(v)!=ring[1].end()&&ring[2].find(u)!=ring[2].end())||(ring[1].find(u)!=ring[1].end()&&ring[2].find(v)!=ring[2].end()&&ring[1].find(v)!=ring[1].end()&&ring[2].find(u)!=ring[2].end())) ans=0;
			}
			puts(ans?"YES":"NO");
		}
		return 0;
	}
 } 
